﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PhatPhucLoc.common;
using PhatPhucLoc.model;
using PhatPhucLoc.dao;

namespace PhatPhucLoc.view
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            String tenDangNhap = txtTenDangNhap.Text.Trim();
            String matKhau = txtMatKhau.Text.Trim();
            if (tenDangNhap == "")
            {
                txtTenDangNhap.Focus();
            }
            else
            {
                if (matKhau == "")
                {
                    txtMatKhau.Focus();
                }
                else
                {
                    ThanhVienModel thanhVienModel = ThanhVienDAO.GetThanhVien(tenDangNhap, matKhau);

                    if (thanhVienModel != null)
                    {
                        if (thanhVienModel.TinhTrang.Equals("1"))
                        {
                            Constants.USER_LOGIN = thanhVienModel;
                            MainForm formMain = new MainForm();
                            this.Visible = false;
                            formMain.Focus();
                            formMain.ShowDialog();
                        }
                        else
                        {
                            MessageBox.Show(this, "Thành viên đã bị khóa !", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                       
                    }
                    else
                    {
                        MessageBox.Show(this, "Đăng Nhập Thất Bại !", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            txtTenDangNhap.Text = "";
            txtMatKhau.Text = "";
            txtTenDangNhap.Focus();
        }

    }
}
